﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BC;
using BE;
namespace SAIN.Configuracion.catalogo
{
    public partial class DataTransactions : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BC.DataFramework.ConnectionsBC cnn = new BC.DataFramework.ConnectionsBC();

                this.DDLConexion.Items.Clear();

                this.DDLConexion.Items.AddRange(
                    (from item in
                         cnn.Select(new BE.DataFramework.ConnectionsBE()
                         {
                             iConnectionId = -1,
                             iConnectorId = -1,
                             sConnectionName = string.Empty,
                             sConnectionString = string.Empty,
                             bActive = true
                         })
                     select new ListItem(item.sConnectionName, item.iConnectionId.ToString())).ToArray<ListItem>());
                this.RefreshGridView();
            }
        }
        protected void CrearTransaction_Click(object sender, EventArgs e)
        {
            try
            {
                BE.DataFramework.DataTransactionsBE dte = new BE.DataFramework.DataTransactionsBE();
                BC.DataFramework.DataTransactionsBC dtc = new BC.DataFramework.DataTransactionsBC();

                dte = this.CapturedTransactionData();

                dtc.Create(dte);

            }
            catch (Exception ex)
            {

            }
        }
        private BE.DataFramework.DataTransactionsBE CapturedTransactionData()
        {
            BE.DataFramework.DataTransactionsBE item = new BE.DataFramework.DataTransactionsBE();
            int connectionId =-1;
            
            item.iConnectionId = string.IsNullOrEmpty(this.DDLConexion.SelectedValue) ? -1 :
                int.TryParse(this.DDLConexion.SelectedValue, out connectionId) ? connectionId : -1;
            item.sName = this.txtNombre.Text;
            item.sProcedureName = this.txtProcedimiento.Text;

            return item;
        }
        private void RefreshGridView()
        {
            BC.DataFramework.DataTransactionsBC dtc = new BC.DataFramework.DataTransactionsBC();

            this.gvDatatransactions.DataSource =
            dtc.Select(new BE.DataFramework.DataTransactionsBE()
            {
                iConnectionId = -1,
                iDataTransactionId = -1,
                sGUID = string.Empty,
                sName = string.Empty,
                sProcedureName = string.Empty
            });
            this.gvDatatransactions.DataBind();
        }

    }
}